<form role="form" id="quickForm" method="post" action="">
    <input type="hidden" name="id" value="{{.model.Id}}">
    {{if eq .model.Id 0}}
    <div class="card-body">
        <div class="form-group">
            <label for="Account">账号</label>
            <input type="text" name="account" class="form-control" id="Account" placeholder="" value="{{.model.Account}}">
        </div>
    </div>
    {{end}}
    <div class="card-body">
        <div class="form-group">
            <label for="nickname">昵称</label>
            <input type="text" name="nickname" class="form-control" id="nickname" placeholder="" value="{{.model.Nickname}}">
        </div>
    </div>
    <div class="card-body">
        <div class="form-group">
            <label for="Email">邮箱</label>
            <input type="text" name="email" class="form-control" id="Email" placeholder="" value="{{.model.Email}}">
        </div>
    </div>
    <!-- /.card-body -->
    <div class="card-footer" style="text-align: center">
        <button type="submit" class="btn btn-primary">提交</button>
        <a href="/admin/admin/index" class="btn btn-danger">返回</a>
    </div>
</form>
<script type="text/javascript">
    let url = "";
    let id = '{{.model.Id}}';
    if (id>0) {
        url = "/admin/api/admin/edit";
    } else {
        url = "/admin/api/admin/create";
    }
    $(document).ready(function () {
        $.validator.setDefaults({
            submitHandler: function (form) {
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: "json",
                    data: $(form).serialize(),
                    beforeSend: function () {

                    },
                    success: function (res) {
                        if (res.code === 1) {
                            Swal.fire(
                                {
                                    icon: 'success',
                                    title: '提示！',
                                    text: '操作成功:)',
                                    showConfirmButton: false,
                                    timer: 1500,
                                    timerProgressBar: true,
                                }
                            ).then((r)=>{
                                window.location.href = '/admin/admin/index'
                            });
                        } else {
                            alert(res.message)
                        }
                    },
                    error: function (e) {
                        let res = JSON.parse(e.responseText);
                        Swal.fire(
                            {
                                icon: 'error',
                                title: '提示！',
                                text: res.message,
                                showConfirmButton: false,
                                timer: 1500,
                                timerProgressBar: true,
                            }
                        )
                    }
                })
            }
        });
        $('#quickForm').validate({
            rules: {
                name: {
                    required: true,
                },
            },
            messages: {
                // name: {
                //     // required: "请输入分类名称",
                // }
            },
            errorElement: 'span',
            errorPlacement: function (error, element) {
                error.addClass('invalid-feedback');
                element.closest('.form-group').append(error);
            },
            highlight: function (element, errorClass, validClass) {
                $(element).addClass('is-invalid');
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).removeClass('is-invalid');
            }
        });
    });
</script>